package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FitDiet;
import com.ruoyi.system.service.IFitDietService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 饮食记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@Controller
@RequestMapping("/system/diet")
public class FitDietController extends BaseController
{
    private String prefix = "system/diet";

    @Autowired
    private IFitDietService fitDietService;

    @RequiresPermissions("system:diet:view")
    @GetMapping()
    public String diet()
    {
        return prefix + "/diet";
    }

    /**
     * 查询饮食记录列表
     */
    @RequiresPermissions("system:diet:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FitDiet fitDiet)
    {
        startPage();
        List<FitDiet> list = fitDietService.selectFitDietList(fitDiet);
        return getDataTable(list);
    }

    /**
     * 导出饮食记录列表
     */
    @RequiresPermissions("system:diet:export")
    @Log(title = "饮食记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FitDiet fitDiet)
    {
        List<FitDiet> list = fitDietService.selectFitDietList(fitDiet);
        ExcelUtil<FitDiet> util = new ExcelUtil<FitDiet>(FitDiet.class);
        return util.exportExcel(list, "饮食记录数据");
    }

    /**
     * 新增饮食记录
     */
    @RequiresPermissions("system:diet:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存饮食记录
     */
    @RequiresPermissions("system:diet:add")
    @Log(title = "饮食记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FitDiet fitDiet)
    {
        return toAjax(fitDietService.insertFitDiet(fitDiet));
    }

    /**
     * 修改饮食记录
     */
    @RequiresPermissions("system:diet:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FitDiet fitDiet = fitDietService.selectFitDietById(id);
        mmap.put("fitDiet", fitDiet);
        return prefix + "/edit";
    }

    /**
     * 修改保存饮食记录
     */
    @RequiresPermissions("system:diet:edit")
    @Log(title = "饮食记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FitDiet fitDiet)
    {
        return toAjax(fitDietService.updateFitDiet(fitDiet));
    }

    /**
     * 删除饮食记录
     */
    @RequiresPermissions("system:diet:remove")
    @Log(title = "饮食记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fitDietService.deleteFitDietByIds(ids));
    }
}
